package Logicamente;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import javax.swing.BorderFactory;
import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPasswordField;
import javax.swing.JRadioButton;
import javax.swing.JSeparator;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.EmptyBorder;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class VentanaCrearPartidaA extends javax.swing.JFrame {
	private JLabel jLabel_name;
	private JLabel jLabel_pass;
	private JComboBox jComboBox_dif;
	private JLabel jLabel_intro;
	private JSeparator jSeparator1;
	private JButton jButton_crear;
	private JButton jButton_back;
	private JPasswordField jPasswordField_pass;
	private JRadioButton jRadioButton_pass;
	private JComboBox jComboBox_part;
	private JTextField jTextField_nombre;
	private JLabel jLabel_max;
	private JLabel jLabel_dificultad;
	private JPanelConFondo contentPane;

	{
		//Set Look & Feel
		try {
			javax.swing.UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
		} catch(Exception e) {
			e.printStackTrace();
		}
	}


	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				VentanaCrearPartidaA inst = new VentanaCrearPartidaA(null);
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public VentanaCrearPartidaA(Usuario u) {
		super();
		contentPane = new JPanelConFondo("/Imagenes/fondo.jpg");
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		initGUI(u);
	}
	
	private void initGUI(final Usuario u) {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				jLabel_name = new JLabel();
				getContentPane().add(jLabel_name);
				jLabel_name.setText("Nombre");
				jLabel_name.setBounds(28, 61, 58, 19);
				jLabel_name.setFont(new java.awt.Font("SansSerif",1,14));
			}
			{
				jLabel_dificultad = new JLabel();
				getContentPane().add(jLabel_dificultad);
				jLabel_dificultad.setText("Dificultad");
				jLabel_dificultad.setBounds(26, 115, 66, 16);
				jLabel_dificultad.setFont(new java.awt.Font("SansSerif",1,14));
			}
			{
				jLabel_pass = new JLabel();
				getContentPane().add(jLabel_pass);
				jLabel_pass.setText("Password");
				jLabel_pass.setBounds(27, 183, 71, 16);
				jLabel_pass.setFont(new java.awt.Font("SansSerif",1,14));
			}
			{
				jLabel_max = new JLabel();
				getContentPane().add(jLabel_max);
				jLabel_max.setText("Cantidad de participantes");
				jLabel_max.setBounds(228, 115, 183, 16);
				jLabel_max.setFont(new java.awt.Font("SansSerif",1,14));
			}
			{
				jTextField_nombre = new JTextField();
				getContentPane().add(jTextField_nombre);
				jTextField_nombre.setText("Ingrese el nombre de la partida");
				jTextField_nombre.setBounds(101, 55, 308, 28);
				jTextField_nombre.addMouseListener(new MouseAdapter(){
	            	   
					public void mouseClicked( MouseEvent e ) { 
	            	         limpiarTexto(e,e.getComponent());
	            	      }				
	               });
			}
			{
				ComboBoxModel jComboBox_difModel = 
						new DefaultComboBoxModel(
								new String[] { "Principiante", "Moderada" , "Dificil" , "Experto" });
				jComboBox_dif = new JComboBox();
				getContentPane().add(jComboBox_dif);
				jComboBox_dif.setModel(jComboBox_difModel);
				jComboBox_dif.setBounds(101, 110, 124, 26);
			}
			{
				ComboBoxModel jComboBox_partModel = 
						new DefaultComboBoxModel(
								new String[] { "1", "2" , "3" ,"4","5","6","7","8","9","10" });
				jComboBox_part = new JComboBox();
				getContentPane().add(jComboBox_part);
				jComboBox_part.setModel(jComboBox_partModel);
				jComboBox_part.setBounds(411, 113, 62, 20);
			}
			{
				jRadioButton_pass = new JRadioButton();
				getContentPane().add(jRadioButton_pass);
				jRadioButton_pass.setBounds(118, 182, 24, 18);
				jRadioButton_pass.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jRadioButton_passActionPerformed(evt);
					}
				});

			}
			{
				jPasswordField_pass = new JPasswordField();
				getContentPane().add(jPasswordField_pass);
				jPasswordField_pass.setBounds(172, 177, 156, 28);
				jPasswordField_pass.setEchoChar((char) 0);
				jPasswordField_pass.setText("Ingrese Password");				
				jPasswordField_pass.addMouseListener(new MouseAdapter(){
	            	   
					public void mouseClicked( MouseEvent e ) { 
	            	         limpiarTexto(e,e.getComponent());
	            	      }				
	               });
				jPasswordField_pass.setVisible(false);
			}
			{
				jButton_back = new JButton();
				getContentPane().add(jButton_back);
				jButton_back.setText("Volver");
				jButton_back.setBounds(62, 274, 90, 28);
				jButton_back.setFont(new java.awt.Font("SansSerif",1,14));
			}
			{
				jButton_crear = new JButton();
				getContentPane().add(jButton_crear);
				jButton_crear.setText("Crear Partida");
				jButton_crear.setBounds(277, 274, 139, 28);
				jButton_crear.setFont(new java.awt.Font("SansSerif",1,14));
				jButton_crear.addActionListener(new ActionListener() {
					public void actionPerformed(ActionEvent evt) {
						jRadioButton_crearActionPerformed(evt,u);
					}
				});
			}
			
			{
				jLabel_intro = new JLabel();
				getContentPane().add(jLabel_intro);
				jLabel_intro.setText("Crea tu partida");
				jLabel_intro.setBounds(167, 6, 161, 26);
				jLabel_intro.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
				jLabel_intro.setFont(new java.awt.Font("SansSerif",3,22));
			}
			pack();
			this.setSize(494, 368);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
		
		
	}

	protected void jRadioButton_crearActionPerformed(ActionEvent evt, Usuario u) {
		if (u.getNick().equalsIgnoreCase("profe"))
		{
			VentanaCrearPartida2 v = new VentanaCrearPartida2(this);
			v.setLocationRelativeTo(null);
			v.setVisible(true);			
			this.setVisible(false);
		}
		else
		{
			VentanaEsperar v = new VentanaEsperar(new Pregunta("� Cuantas caras tiene un Icosaedro ?", "18","10","20","15",3,20),85,1,0,u
					,new Partida(jTextField_nombre.getText(),(String) jComboBox_dif.getSelectedItem(),(String) jComboBox_part.getSelectedItem()));
			v.setLocationRelativeTo(null);
			v.setVisible(true);			
			this.setVisible(false);
			this.hide();
		}
	}


	protected void jRadioButton_passActionPerformed(ActionEvent evt) {
		if(jRadioButton_pass.isSelected()){
			jPasswordField_pass.setVisible(true);
		}
		else{
			jPasswordField_pass.setVisible(false);
		}
		
	}

	protected void limpiarTexto(MouseEvent e, Component component) {
		JTextField txt = (JTextField) component;
		if(txt.getText().equalsIgnoreCase("Ingrese Password")){
			((JPasswordField) txt).setEchoChar('*');
		}
		txt.setText("");		
	}

}
